package com.atguigu.yygh.order.controller;


import com.atguigu.yygh.common.R;
import com.atguigu.yygh.common.utils.AuthContextHolder;
import com.atguigu.yygh.enums.OrderStatusEnum;
import com.atguigu.yygh.model.order.OrderInfo;
import com.atguigu.yygh.order.service.OrderService;
import com.atguigu.yygh.vo.order.OrderQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author zhmwi
 * @Date 2021/7/21
 * @Dersciption
 */
@Api("处理订单请求")
@RequestMapping("/api/order/orderInfo")
@RestController
public class ApiOrderController {
    @Autowired
    private OrderService orderService;

    //下单跨模块 查询病人 查询医院
    @ApiOperation("拿到排班id 病人id创建订单")
    @PostMapping("auth/submitOrder/{scheduleId}/{patientId}")
    public R submitOrder(@PathVariable String scheduleId,
                         @PathVariable Long patientId){
        Long orderId = orderService.saveOrder(scheduleId,patientId);
        return R.ok().data("orderId",orderId);
    }

    //查询订单列表
    @ApiOperation("带条件带分页查询订单列表")
    @GetMapping("/auth/{page}/{limit}")
    public  R list(@PathVariable Long page,
                   @PathVariable Long limit,
                   OrderQueryVo orderQueryVo,
                   HttpServletRequest request){
        //设置当前用户id
        Long userId = AuthContextHolder.getUserId(request);
        orderQueryVo.setUserId(userId);
        Page<OrderInfo> pageParam = new Page<OrderInfo>(page, limit);
        IPage<OrderInfo> pageModel = orderService.selectPage(pageParam,orderQueryVo);
        return R.ok().data("pageModel",pageModel);
    }

    //获取订单状态
    @ApiOperation("获取订单状态")
    @GetMapping("auth/getStatusList")
    public R getStatusList(){
        return R.ok().data("statusList", OrderStatusEnum.getStatusList());
    }
}
